SpringBoot官方文档翻译(四):安装Spring Boot命令行界面

10.2 Installing the Spring Boot CLI(安装Spring Boot命令行界面)

1
2
3
4
5
6
7
The Spring Boot CLI (Command Line Interface) is a command line tool    
that you can use to quickly prototype with Spring. It lets you
run Groovy scripts, which means that you have a familiar Java-like
syntax without so much boilerplate code.
You do not need to use the CLI to work with Spring Boot, but
it is definitely the quickest way to get a Spring application
off the ground.

Spring Boot CLI(命令行界面)是一个命令行工具,您可以使用它来快速使用Spring进行原型开发
它允许您运行Groovy脚本,这意味着您不需要太多样板代码就能以类似于java的语法进行开发。
尽管您不需要使用CLI去运行Spring Boot ,但这绝对是获得Spring应用程序的最快捷方式

10.2.1 Manual Installation(手动安装)

1
2
3
4
5
6
7
8
9
10
You can download the Spring CLI distribution from the Spring     
software repository:
• spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.zip
• spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.tar.gz
Cutting edge snapshot distributions are also available.
Once downloaded, follow the INSTALL.txt instructions from the
unpacked archive. In summary, there is a spring script (spring.bat 
for Windows) in a bin/directory in the .zip file. Alternatively,
you can use java -jar with the .jar file (the script helps you to
be sure that the classpath is set correctly).

您可以从Spring 软件远程库下载Spring CLI的分发版本
• spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.zip
• spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin.tar.gz
最新的快照版本同样可用。下载以后,请参照解压出来的文档INSTALL.txt的介绍进行操作。综上所述,有一个spring脚本(windows 下用spring.bat)在bin目录下的.zip文件中。另外,你可以使用java -jar 启动.jar包(这个脚本帮助您确认类路径是否被正确设置)

10.2.2 Installation with SDKMAN!(通过SDKMAN安装)

1
2
3
4
SDKMAN! (The Software Development Kit Manager) can be used for     
managing multiple versions of various binary SDKs, including Groovy
and the Spring Boot CLI. Get SDKMAN! from sdkman.io and install
Spring Boot by using the following commands:

SDKMAN!(软件开发工具包管理器)可用于管理各种二进制SDK的多个版本,包括Groovy脚本和Spring Boot CLI.从sdkman.io中获取SDKMAN!并用以下命令进行Spring Boot 安装。

1
2
3
$ sdk install springboot
$ spring --version
Spring Boot v2.1.0.BUILD-SNAPSHOT

1
2
If you develop features for the CLI and want easy access     
to the version you built, use the following commands:

如果您为CLI开发功能并希望轻松访问您创建的版本,请使用以下命令:

1
2
3
4
5
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/    
target/spring-boot-cli-2.1.0.BUILD-SNAPSHOT-bin/spring-2.1.0.BUILD-SNAPSHOT/
$ sdk default springboot dev
$ spring --version
Spring CLI v2.1.0.BUILD-SNAPSHOT
1
2
The preceding instructions install a local instance of spring called the dev instance. It points at your target build location, so every time you rebuild Spring Boot,spring is up-to-date.
You can see it by running the following command:

之前介绍了如何安装一个被称之为dev实例的本地spring实例。它指向了您的目标构建地址,因此每次当您重新构建Spring Boot的时候spring也同步更新。您可以通过运行下列命令行查看它:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sdk ls springboot

================================================================================
Available Springboot Versions
================================================================================
> + dev
* 2.1.0.BUILD-SNAPSHOT

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

10.2.3 OSX Homebrew Installation(苹果系统下使用Homebrew安装)

1
2
If you are on a Mac and use Homebrew, you can install the     
Spring Boot CLI by using the following commands:

如果您使用的是Mac并且使用Homebrew命令,你可以安装Spring Boot CLI 通过以下命令:

1
2
$ brew tap pivotal/tap
$ brew install springboot
1
Homebrew installs spring to /usr/local/bin.

Homebrew将spring安装在/usr/local/bin路径下

1
2
If you do not see the formula, your installation of brew     
might be out-of-date. In that case, run brew update and try again.

如果您没有看到该公式,那么您的brew的安装可能会过时。 在这种情况下,运行brew update并重试。

10.2.4 MacPorts Installation(以MacPorts安装方式)

1
2
If you are on a Mac and use MacPorts, you can install the     
Spring Boot CLI by using the following command:

如果您使用Mac,并且使用MacPorts,您可以通过以下命令安装Spring Boot CLI

1
$ sudo port install spring-boot-cli

10.2.5 Command-line Completion(命令行完成)

1
2
3
4
5
6
7
8
9
The Spring Boot CLI includes scripts that provide command     
completion for the BASH and zsh shells. You can source 
the script (also named spring) in any shell or put it in
your personal or system-wide bash completion initialization.
On a Debian system, the system-wide scripts are in 
/shell-completion/bash and all scripts in that directory
are executed when a new shell starts. For example, to run
the script manually if you have installed by using SDKMAN!,
use the following commands:

Spring Boot CLI为BASH和zsh shells提供了命令行完成脚本。您可以在任何shell或者您个人的或者系统范围内的bash中初始化source该脚本。在Debian系统,全系统脚本在/shell-completion/bash,并且所有新建的可执行脚本都在该路径下。比如说,在您已经安装使用SDKMAN的情况下,去手动运行该脚本,使用如下命令:

1
2
3
$ . ~/.sdkman/candidates/springboot/current/shell-completion/bash/spring
$ spring <HIT TAB HERE>
grab help jar run test version

1
2
3
If you install the Spring Boot CLI by using Homebrew or MacPorts,     
the command-line completion scripts are automatically registered
with your shell.

如果您使用Homebrew或者MacPorts安装Spring Boot CLI命令行初始化完成,那么它会自动注册到您的shell当中。

10.2.6 Quick-start Spring CLI Example(快速开始Spring CLI 示例)

1
2
You can use the following web application to test your installation.     
To start, create a file called app.groovy, as follows:

您可以使用如下的web应用去测试您的安装情况。首先,创建一个如下的app.groovy:

1
2
3
4
5
6
7
8
9
@RestController
class ThisWillActuallyRun {

@RequestMapping("/")
String home() {
"Hello World!"
}

}
1
Then run it from a shell, as follows:

然后在shell中运行它,如下:

1
$ spring run app.groovy

1
2
The first run of your application is slow, as dependencies     
are downloaded. Subsequent runs are much quicker.

首次运行您的应用会比较慢,因为依赖库需要被下载,以后每次运行会比较快

1
2
Open localhost:8080 in your favorite web browser.     
You should see the following output:

在您喜爱的浏览器中打开 localhost:8080 ,您将会看到如下的输出:

1
Hello World!

10.3 Upgrading from an Earlier Version of Spring Boot(从一个旧版本升级Spring Boot)

1
2
3
4
If you are upgrading from an earlier release of Spring Boot, check     
the “migration guide” on the project wiki that provides detailed
upgrade instructions. Check also the“release notes” for a list of
“new and noteworthy” features for each release.

如果您想从以前的版本中升级Spring Boot 请核对该项目在wiki上的“migration guide”,它提供了详细的升级说明。并且从列表中核对“relese notes”,每个relese版本都有新的值得注意的功能。

1
2
3
4
5
To upgrade an existing CLI installation, use the appropriate     
package manager command (for example, brew upgrade) or, if
you manually installed the CLI, follow thestandard instructions,
remembering to update your PATH environment variable to
remove any older references.

去升级一个已有的CLI安装程序,推荐使用打包工具命令(比如 brew upgrage),如果您手动安装了CLI,根据标准的说明,记得更新您的环境变量去移除任何旧的关联

分享到